//
//  Singleton.h
//  Musci_Demo
//
//  Created by 刘表聪 on 15/8/9.
//  Copyright (c) 2015年 刘表聪. All rights reserved.
//

#ifndef Musci_Demo_Singleton_h
#define Musci_Demo_Singleton_h

// 写在.h 文件中
#define singleton_interface(className) \
+ (className *)shared##className;

// 写在.m文件中
#define singleton_implementation(className) \
static className *_instance; \
+ (className *)shared##className \
{ \
static dispatch_once_t onceToken; \
dispatch_once(&onceToken, ^{ \
_instance = [[[self class] alloc] init]; \
}); \
return _instance; \
} \
+ (id)allocWithZone:(NSZone *)zone \
{ \
static dispatch_once_t onceToken; \
dispatch_once(&onceToken, ^{ \
_instance = [super allocWithZone:zone]; \
}); \
return _instance; \
} \


#endif /* Singleton_h */
